<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/page/common/commonPage.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>内置模板管理</title>
    <link rel="stylesheet" type="text/css" href="${resourcesUrl}/common/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="${resourcesUrl}/common/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="${resourcesUrl}/common/css/smartadmin-production.min.css">
</head>
<body>
    <%@ include file="/WEB-INF/page/common/header.jsp"%>
    <%@ include file="/WEB-INF/page/common/leftSideBar.jsp"%>

    <div id="main" role="main">
        <div id="ribbon">
            <ol class="breadcrumb">
                <li>首页</li>
                <li>内置模板管理</li>
            </ol>
        </div>
        <div id="content">
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                    <div class="jarviswidget">
                        <header>
                            <h2><i class="fa fa-list"></i> 内置模板列表</h2>
                        </header>
                        <div class="widget-body">
                            <table class="table table-bordered table-striped table-hover">
                                <thead>
                                    <tr>
                                        <th>模板文件</th>
                                        <th>模板名称</th>
                                        <th>模板类型</th>
                                        <th>模板说明</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <c:forEach items="${templates}" var="template">
                                        <tr>
                                            <td>${template.tplFile}</td>
                                            <td>${template.tplName}</td>
                                            <td>${template.tplType}</td>
                                            <td>${template.tplDesc}</td>
                                            <td>
                                                <button type="button" class="btn btn-primary btn-xs" onclick="editTemplate('${template.tplFile}')">
                                                    <i class="fa fa-pencil"></i> 修改
                                                </button>
                                                <button type="button" class="btn btn-danger btn-xs" onclick="deleteTemplate('${template.tplFile}')">
                                                    <i class="fa fa-trash-o"></i> 删除
                                                </button>
                                            </td>
                                        </tr>
                                    </c:forEach>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="${resourcesUrl}/common/js/jquery-1.8.2.min.js"></script>
    <script src="${resourcesUrl}/common/js/bootstrap/bootstrap.min.js"></script>
    <script src="${resourcesUrl}/common/components/artDialog/dialog-min.js"></script>
    <script type="text/javascript">
        function editTemplate(tplFile) {
            window.location.href = '${base}/template/edit?tplFile=' + tplFile;
        }
        
        function deleteTemplate(tplFile) {
            art.dialog({
                content: '确定要删除该模板吗？',
                ok: function() {
                    $.ajax({
                        url: '${base}/template/delete',
                        type: 'POST',
                        data: {
                            tplFile: tplFile
                        },
                        success: function(data) {
                            if(data.RET_CODE.toLowerCase() === 'success') {
                                art.dialog({
                                    content: data.RET_OBJ,
                                    ok: function() {
                                        window.location.reload();
                                    }
                                });
                            } else {
                                art.dialog.alert(data.RET_OBJ || '删除失败');
                            }
                        }
                    });
                },
                cancel: true
            });
        }
    </script>
    <%@ include file="/WEB-INF/page/common/footer.jsp"%>
</body>
</html> 